var $mInlineMsg = array();
var $mTemplateIds = array();
+ var $mImageTimeKeys = array();
# What level of 'untrustworthiness' is allowed in CSS/JS modules loaded on this page?
# @see ResourceLoaderModule::$origin
$this->mNoGallery = $parserOutput->getNoGallery();
$this->mHeadItems = array_merge( $this->mHeadItems, $parserOutput->getHeadItems() );
$this->addModules( $parserOutput->getModules() );
- // Versioning...
- foreach ( (array)$parserOutput->mTemplateIds as $ns => $dbks ) {
+
+ // Template versioning...
+ foreach ( (array)$parserOutput->getTemplateIds() as $ns => $dbks ) {
if ( isset( $this->mTemplateIds[$ns] ) ) {
$this->mTemplateIds[$ns] = $dbks + $this->mTemplateIds[$ns];
} else {
$this->mTemplateIds[$ns] = $dbks;
}
}
+ // File versioning...
+ foreach ( (array)$parserOutput->getImageTimeKeys() as $dbk => $data ) {
+ $this->mImageTimeKeys[$dbk] = $data;
+ }
// Hooks registered in the object
global $wgParserOutputHooks;
* changes in an incompatible way, so the parser cache
* can automatically discard old data.
*/
- const VERSION = '1.6.4';
+ const VERSION = '1.6.5';
/**
* Update this version number when the output of serialiseHalfParsedText()
}
wfProfileOut( __METHOD__."-image" );
continue;
-
}
if ( $ns == NS_CATEGORY ) {
wfRunHooks( 'BeforeParserMakeImageLinkObj',
array( &$this, &$nt, &$skip, &$time, &$descQuery, &$sha1 ) );
if ( $skip ) {
- $this->mOutput->addImage( $nt->getDBkey() ); // register
+ $this->mOutput->addImage( $nt->getDBkey(), null, null ); // register
$link = $sk->link( $nt );
} else {
- # Fetch and register the file
- $file = $this->fetchFile( $nt, $time, $sha1 );
- if ( $file ) {
- $nt = $file->getTitle(); // file title may be different (via hooks)
- }
+ # Fetch and register the file (file title may be different via hooks)
+ list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $time, $sha1 );
$link = $sk->makeMediaLinkFile( $nt, $file, $text );
}
# Cloak with NOPARSE to avoid replacement in replaceExternalLinks
/**
* Fetch the unparsed text of a template and register a reference to it.
+ * @param Title $title
+ * @return Array ( string or false, Title )
*/
function fetchTemplateAndTitle( $title ) {
$templateCb = $this->mOptions->getTemplateCallback(); # Defaults to Parser::statelessFetchTemplate()
return array( $text, $finalTitle );
}
+ /**
+ * Fetch the unparsed text of a template and register a reference to it.
+ * @param Title $title
+ * @return mixed string or false
+ */
function fetchTemplate( $title ) {
$rv = $this->fetchTemplateAndTitle( $title );
return $rv[0];
}
/**
- * Fetch a file and register a reference to it.
- * @TODO: register and track file version info too
+ * Fetch a file and its title and register a reference to it.
+ * @param Title $title
+ * @param string $time MW timestamp
+ * @param string $sha1 base 36 SHA-1
+ * @return mixed File or false
*/
function fetchFile( $title, $time = false, $sha1 = false ) {
- if ( $sha1 ) { // get by (sha1,timestamp)
+ $res = $this->fetchFileAndTitle( $title, $time, $sha1 );
+ return $res[0];
+ }
+
+ /**
+ * Fetch a file and its title and register a reference to it.
+ * @param Title $title
+ * @param string $time MW timestamp
+ * @param string $sha1 base 36 SHA-1
+ * @return Array ( File or false, Title )
+ */
+ function fetchFileAndTitle( $title, $time = false, $sha1 = false ) {
+ if ( $time === '0' ) {
+ $file = false; // broken thumbnail forced by hook
+ } elseif ( $sha1 ) { // get by (sha1,timestamp)
$file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) );
if ( $file ) {
$title = $file->getTitle(); // file title may not match $title
} else { // get by (name,timestamp)
$file = wfFindFile( $title, array( 'time' => $time ) );
}
- $this->mOutput->addImage( $title->getDBkey() );
- return $file;
+ # Register the file as a dependancy
+ $time = $file ? $file->getTimestamp() : null;
+ $sha1 = $file ? $file->getSha1() : null;
+ $this->mOutput->addImage( $title->getDBkey(), $time, $sha1 );
+
+ return array( $file, $title );
}
/**
wfRunHooks( 'BeforeParserMakeImageLinkObj',
array( &$this, &$title, &$skip, &$time, &$descQuery, &$sha1 ) );
if ( $skip ) {
- $this->mOutput->addImage( $title->getDBkey() ); // register
+ $this->mOutput->addImage( $title->getDBkey(), null, null ); // register
return $sk->link( $title );
}
- # Fetch and register the file
- $file = $this->fetchFile( $title, $time, $sha1 );
- if ( $file ) {
- $title = $file->getTitle(); // file title may be different (via hooks)
- }
+ # Fetch and register the file (file title may be different via hooks)
+ list( $file, $title ) = $this->fetchFileAndTitle( $title, $time, $sha1 );
# Get parameter map
$handler = $file ? $file->getHandler() : false;
$mTemplates = array(), # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
$mTemplateIds = array(), # 2-D map of NS/DBK to rev ID for the template references. ID=zero for broken.
$mImages = array(), # DB keys of the images used, in the array key only
+ $mImageTimeKeys = array(), # DB keys of the images used mapped to sha1 and MW timestamp
$mExternalLinks = array(), # External link URLs, in the key only
$mInterwikiLinks = array(), # 2-D map of prefix/DBK (in keys only) for the inline interwiki links in the document.
$mNewSection = false, # Show a new section link?
function getEditSectionTokens() { return $this->mEditSectionTokens; }
function &getLinks() { return $this->mLinks; }
function &getTemplates() { return $this->mTemplates; }
+ function &getTemplateIds() { return $this->mTemplateIds; }
function &getImages() { return $this->mImages; }
+ function &getImageTimeKeys() { return $this->mImageTimeKeys; }
function &getExternalLinks() { return $this->mExternalLinks; }
function getNoGallery() { return $this->mNoGallery; }
function getHeadItems() { return $this->mHeadItems; }
$this->mLinks[$ns][$dbk] = $id;
}
- function addImage( $name ) {
+ /**
+ * @param $name string Title dbKey
+ * @param $timestamp string MW timestamp of file creation
+ * @param $sha string base 36 SHA-1 of file
+ * @return void
+ */
+ function addImage( $name, $timestamp, $sha1 ) {
$this->mImages[$name] = 1;
+ $this->mImageTimeKeys[$name] = array( 'time' => $timestamp, 'sha1' => $sha1 );
}
/**
* @param $title Title
- * @param $page_id
- * @param $rev_id
+ * @param $page_id
+ * @param $rev_id
* @return void
*/
function addTemplate( $title, $page_id, $rev_id ) {